//
//  YBLoginViewController.m
//  YBWifiAuthSDK
//
//  Created by yiban on 16/1/21.
//  Copyright © 2016年 yiban. All rights reserved.
//

#import "YBLoginViewController.h"
#import "YBRegisterViewController.h"
#import "YBDevice.h"

@interface YBLoginViewController ()

@end

@implementation YBLoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self initUI];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)dealloc
{
    
}
///////////////////////////////
-(void)initUI
{
    UIImage *imgLoginBKG = [UIImage imageWithContentsOfFile:[YBDevice bundleImagePath:@"bg_login" type:@"tiff"]];
    UIImageView *viewBKG = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
    [viewBKG setImage:imgLoginBKG];
    [viewBKG setUserInteractionEnabled:YES];
    [self.view addSubview:viewBKG];
    
    UIView *maskView = [[UIView alloc] init];
    maskView.backgroundColor = [YBDevice colorWithHex:@"333333"];
    maskView.alpha = 0.3;
    [self.view addSubview:maskView];
    maskView.frame = self.view.frame;
    
    UIView *viewGoolei = [[UIView alloc] initWithFrame:viewBKG.bounds];
    [viewGoolei setBackgroundColor:[UIColor blackColor]];
    [viewGoolei setAlpha:0];
    [self.view addSubview:viewGoolei];
    
    NSInteger nBoundSizeType = [YBDevice boundSizeType];
    float fStart = 0;
    
    if (nBoundSizeType == 0) {
        fStart = - 40;
    }
    
    if (nBoundSizeType == 1) {
        fStart =  60;
    }
    if (nBoundSizeType == 2) {
        fStart =  40;
    }
    
    if (nBoundSizeType == 2) {
        fStart =  60;
    }
    
    //////RELEASE(_imgLogo);
    
    UIImageView *touming = [[UIImageView alloc] init];
    touming.frame = CGRectMake( 10, 185+fStart, self.view.frame.size.width - 20, 230);
    touming.image = [UIImage imageWithContentsOfFile:[YBDevice bundleImagePath:@"login_touming" type:@"tiff"]];
    [self.view addSubview:touming];
    
    UIImageView *logo_bear = [[UIImageView alloc] init];
    UIImage *bear = [UIImage imageWithContentsOfFile:[YBDevice bundleImagePath:@"bear_1509" type:@"tiff"]];
    logo_bear.frame = CGRectMake( 10, 187 + fStart - (self.view.frame.size.width - 20) /2.054, self.view.frame.size.width - 20, (self.view.frame.size.width - 20) /2.054);
    logo_bear.image = bear;
    
    [self.view addSubview:logo_bear];
    //
    UIImageView *phone_kuang = [[UIImageView alloc] initWithImage: [UIImage imageWithContentsOfFile:[YBDevice bundleImagePath:@"text_p" type:@"tiff"]]];
    phone_kuang.frame = CGRectMake(35, 215+fStart, self.view.frame.size.width - 70, 40);
    [self.view addSubview:phone_kuang];
    
    
    UITextField *phoneNoInput = [[UITextField alloc] initWithFrame:CGRectMake(75, 215+fStart, self.view.frame.size.width - 150 + 5, 40)];
    [phoneNoInput setBackgroundColor:[UIColor clearColor]];
    phoneNoInput.text = [[NSUserDefaults standardUserDefaults] stringForKey:@"username"];
    [phoneNoInput setPlaceholder:@"手机号/邮箱"];
    [phoneNoInput setTextAlignment:NSTextAlignmentLeft];
    [phoneNoInput setFont:[UIFont boldSystemFontOfSize:13]];
    [phoneNoInput setKeyboardType:UIKeyboardTypeEmailAddress];
    [phoneNoInput setReturnKeyType:UIReturnKeyNext];
    
    [phoneNoInput setTag:901];
    
    [phoneNoInput setValue:[YBDevice colorWithHex:@"888888"] forKeyPath:@"_placeholderLabel.textColor"];
    [phoneNoInput setValue:[UIFont boldSystemFontOfSize:13] forKeyPath:@"_placeholderLabel.font"];
    phoneNoInput.textColor = [UIColor blackColor];
    [self.view addSubview:phoneNoInput];
    
    UIImageView *imgPhone = [[UIImageView alloc] init];
    imgPhone.image = [UIImage imageWithContentsOfFile:[YBDevice bundleImagePath:@"user_phone" type:@"tiff"]];
    imgPhone.frame = CGRectMake(50, phoneNoInput.frame.origin.y + 12.5, 15, 15);
    [self.view addSubview:imgPhone];
    
    UIImage *_logo =  [UIImage imageWithContentsOfFile:[YBDevice bundleImagePath:@"fenge" type:@"tiff"]];
    UIImageView *img_Logo = [[UIImageView alloc] initWithFrame:CGRectMake(70, 225+fStart , 0.5, 20)];
    [img_Logo setBackgroundColor:[UIColor clearColor]];
    [img_Logo setImage:_logo];
    [self.view addSubview:img_Logo];
    
    
    //////RELEASE(_phoneNoInput);
    
    UIImageView *ps_kuang = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:[YBDevice bundleImagePath:@"text_p" type:@"tiff"]]];
    ps_kuang.frame = CGRectMake(35, 270+fStart, self.view.frame.size.width - 70, 40);
    [self.view addSubview:ps_kuang];
    
    UIImageView *img_Logo2 = [[UIImageView alloc] initWithFrame:CGRectMake(70, 280+fStart , 0.5, 20)];
    [img_Logo2 setBackgroundColor:[UIColor clearColor]];
    [img_Logo2 setImage:_logo];
    [self.view addSubview:img_Logo2];
    
    UITextField *pswInput = [[UITextField alloc] initWithFrame:CGRectMake(75, 270+fStart, self.view.frame.size.width - 150 + 5, 40)];
    [pswInput setBackgroundColor:[UIColor clearColor]];
    pswInput.text = [[NSUserDefaults standardUserDefaults] stringForKey:@"password"];
    [pswInput setPlaceholder:@"输入密码"];
    [pswInput setTextAlignment:NSTextAlignmentLeft];
    [pswInput setFont:[UIFont boldSystemFontOfSize:13]];
    [pswInput setSecureTextEntry:YES];
    [pswInput setTag:902];
    [pswInput setValue:[YBDevice colorWithHex:@"888888"] forKeyPath:@"_placeholderLabel.textColor"];
    [pswInput setValue:[UIFont boldSystemFontOfSize:13] forKeyPath:@"_placeholderLabel.font"];
    pswInput.textColor = [UIColor blackColor];
    [self.view addSubview:pswInput];
    
    UIImageView *_imgLogo = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0 , 320, 200)];
    [_imgLogo setBackgroundColor:[UIColor clearColor]];
    
    UIImageView *imgPs = [[UIImageView alloc] init];
    imgPs.image = [UIImage imageWithContentsOfFile:[YBDevice bundleImagePath:@"user_ps" type:@"tiff"]];
    imgPs.frame = CGRectMake(50, pswInput.frame.origin.y + 12.5, 15, 15);
    [self.view addSubview:imgPs];
    
    
    UIButton *_btnLogin = [[UIButton alloc] initWithFrame:CGRectMake(35, 360+fStart, self.view.frame.size.width - 70, 40)];
    [_btnLogin setBackgroundColor:[UIColor clearColor]];
    [_btnLogin setTitle:@"登录" forState:UIControlStateNormal];
    [_btnLogin setTitleColor:[YBDevice colorWithHex:@"ffffff"] forState:UIControlStateNormal];
    [_btnLogin setImage:[UIImage imageWithContentsOfFile:[YBDevice bundleImagePath:@"blueBtn@2x" type:@"png"]] forState:UIControlStateNormal];
    [_btnLogin setImage:[UIImage imageWithContentsOfFile:[YBDevice bundleImagePath:@"blueBtn_sel@2x" type:@"png"]] forState:UIControlStateHighlighted];
    if (nBoundSizeType == 1) {
        [_btnLogin setImage:[UIImage imageWithContentsOfFile:[YBDevice bundleImagePath:@"blueBtn6p@2x" type:@"png"]] forState:UIControlStateNormal];
        [_btnLogin setImage:[UIImage imageWithContentsOfFile:[YBDevice bundleImagePath:@"blueBtn6p_sel@2x" type:@"png"]] forState:UIControlStateHighlighted];
    }
    if (nBoundSizeType == 2) {
        [_btnLogin setImage:[UIImage imageWithContentsOfFile:[YBDevice bundleImagePath:@"blueBtn6@2x" type:@"png"]] forState:UIControlStateNormal];
        [_btnLogin setImage:[UIImage imageWithContentsOfFile:[YBDevice bundleImagePath:@"blueBtn6_sel@2x" type:@"png"]] forState:UIControlStateHighlighted];
    }
    [_btnLogin.titleLabel setFont:[YBDevice YBFoutStyle:15]];
    [_btnLogin addTarget:self action:@selector(loginButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [_btnLogin.layer setCornerRadius:4];
    [self.view addSubview:_btnLogin];
    
    
    UIImage *kefuImage = [UIImage imageWithContentsOfFile:[YBDevice bundleImagePath:@"kefu" type:@"tiff"]];
    UIButton *kefuButton = [[UIButton alloc] init];
    [kefuButton setImage:kefuImage forState:UIControlStateNormal];
    kefuButton.frame = CGRectMake(self.view.frame.size.width - 46, 34, 36, 36);
    [kefuButton addTarget:self action:@selector(kefuButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    if ([[YBDevice platform] isEqualToString:@"iphone"]) {
        [self.view addSubview:kefuButton];
    }
    
    
    UIButton *zhuceBtn = [[UIButton alloc] init];
    zhuceBtn.frame = CGRectMake(35 , 317+fStart, 50, 20);
    
    zhuceBtn.backgroundColor = [UIColor clearColor];
    [zhuceBtn.titleLabel setFont:[YBDevice YBFoutStyle:12]];
    [zhuceBtn setTitleColor:[YBDevice colorWithHex:@"888888"] forState:UIControlStateNormal];
    [zhuceBtn setTitle:@"没有帐号" forState:UIControlStateNormal];
    [zhuceBtn addTarget:self action:@selector(zhuceButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:zhuceBtn];
    
    
    UIButton *forgetBtn = [[UIButton alloc] init];
    forgetBtn.frame = CGRectMake(self.view.frame.size.width - 35 - 50 , 317+fStart, 50, 20);
 
    [forgetBtn setTitle:@"忘记密码" forState:UIControlStateNormal];
    forgetBtn.backgroundColor = [UIColor clearColor];
    [forgetBtn.titleLabel setFont:[YBDevice YBFoutStyle:12]];
    [forgetBtn setTitleColor:[YBDevice colorWithHex:@"888888"] forState:UIControlStateNormal];
    [forgetBtn addTarget:self action:@selector(forgetButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:forgetBtn];
    ////[touming release];
}
-(void)loginButtonClick:(id)sender
{
    
}
-(void)zhuceButtonClick:(id)sender
{
    YBRegisterViewController *regist = [YBRegisterViewController newWithDelegate:_delegate];
    [self.navigationController pushViewController:regist animated:YES];
}
-(void)forgetButtonClick:(id)sender
{
    
}
-(void)kefuButtonClick:(id)sender
{
    
}
@end
